
 <!DOCTYPE HTML>
<html lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
  
    <title>flying 最新版本新增特性 | my bat is flying in Aurora</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="limeng32">
    

    
    <meta name="description" content="本节内容向您讲解最新版本新增特性">
<meta property="og:type" content="article">
<meta property="og:title" content="flying 最新版本新增特性">
<meta property="og:url" content="http://flying-doc.limeng32.com/2017/04/15/2017-04-15-flying 最新版本新增特性/index.html">
<meta property="og:site_name" content="my bat is flying in Aurora">
<meta property="og:description" content="本节内容向您讲解最新版本新增特性">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2021-06-06T06:42:01.952Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="flying 最新版本新增特性">
<meta name="twitter:description" content="本节内容向您讲解最新版本新增特性">

    
    <link rel="alternative" href="/atom.xml" title="my bat is flying in Aurora" type="application/atom+xml">
    
    
    
    <link rel="stylesheet" href="/css/style.css">
</head>
</html>
  <body>
    <header>
      
<div>
		
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="my bat is flying in Aurora">my bat is flying in Aurora</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="菜单">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/">Home</a></li>
					
						<li><a href="/archives">Archives</a></li>
					
						<li><a href="/about">About</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="搜索" />
						<input type="hidden" name="q" value="site:flying-doc.limeng32.com">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2017/04/15/2017-04-15-flying 最新版本新增特性/" title="flying 最新版本新增特性" itemprop="url">flying 最新版本新增特性</a>
  </h1>
  <p class="article-author">By
       
		<a href="/about" title="limeng32" target="_blank" itemprop="author">limeng32</a>
		
  <p class="article-time">
    <time datetime="2017-04-14T16:00:00.000Z" itemprop="datePublished"> 发表于 2017-04-15</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">文章目录</strong>
		
		<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#极光"><span class="toc-text">极光</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#批量操作"><span class="toc-text">批量操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#按复杂条件修改"><span class="toc-text">按复杂条件修改</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#按复杂条件删除"><span class="toc-text">按复杂条件删除</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#批量新增"><span class="toc-text">批量新增</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#批量更新"><span class="toc-text">批量更新</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#索引"><span class="toc-text">索引</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#代理属性"><span class="toc-text">代理属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#打印日志"><span class="toc-text">打印日志</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#清明"><span class="toc-text">清明</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#支持更复杂的外键关系"><span class="toc-text">支持更复杂的外键关系</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#阳春"><span class="toc-text">阳春</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#customTypeHandler"><span class="toc-text">customTypeHandler</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#初雪"><span class="toc-text">初雪</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#自定义主键生成器"><span class="toc-text">自定义主键生成器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#使用或逻辑查询"><span class="toc-text">使用或逻辑查询</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#普通或逻辑查询"><span class="toc-text">普通或逻辑查询</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#外键或逻辑查询"><span class="toc-text">外键或逻辑查询</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#优化使用体验"><span class="toc-text">优化使用体验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#全面提升代码质量"><span class="toc-text">全面提升代码质量</span></a></li></ol></li></ol>
		
		</div>
		
		<h1 id="极光"><a href="#极光" class="headerlink" title="极光"></a><a href="#极光">极光</a></h1><p>对应 flying 版本号为 <code>1.0.0</code>（适用于 mybatis-3.4.x），主要新增特性如下：</p>
<h2 id="批量操作"><a href="#批量操作" class="headerlink" title="批量操作"></a><a href="#批量操作">批量操作</a></h2><h3 id="按复杂条件修改"><a href="#按复杂条件修改" class="headerlink" title="按复杂条件修改"></a><a href="#按复杂条件修改">按复杂条件修改</a></h3><p>从 <code>1.0.0</code> 开始加入按复杂条件修改操作。因为批量操作的入参要同时描述修改后的状态和参与修改的条件（在修改单条记录时我们只匹配主键），所以此场景下我们采用 <i>pojo_condition</i> 类作为入参。pojo_condition 类是 pojo 类的子类，无需任何改动它就可以完成描述修改后的状态的任务；同时它又可以按需要加入各种 <code>@ConditionMapperAnnotation</code> 注解，以前版本修改操作会忽略这些注解，但从此版本开始这些注解会描述批量修改的条件，它们可以是复杂的组合，如 <code>&lt;&gt;</code>、<code>like</code>、<code>or</code> 等，只要您的数据库支持即可。仍以上一篇文章的AccountCondition为例，在AccountCondition中加入以下属性：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"name"</span>, conditionType = ConditionType.Equals)</span><br><span class="line">    <span class="comment">/*用作 name 完全匹配的值*/</span></span><br><span class="line">    <span class="keyword">private</span> String nameEquals;</span><br><span class="line"><span class="comment">/*相关的getter和setter方法请自行补充*/</span></span><br></pre></td></tr></table></figure></p>
<p>上面的代码看似和 Account 原有的 name 属性功能重复，但实际上因为它有 @ConditionMapperAnnotation 注解，在 update 操作时可以作为批量处理条件：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">AccountCondition ac = <span class="keyword">new</span> AccountCondition();</span><br><span class="line">ac.setNameEqual(<span class="string">"ann"</span>);</span><br><span class="line">ac.setName(<span class="string">"bob"</span>);</span><br><span class="line"><span class="comment">/*将所有姓名为 ann 的用户都更名为 bob*/</span></span><br><span class="line">accountService.update(ac);</span><br></pre></td></tr></table></figure></p>
<p>以上只是最简单的批量修改，当您理解这个机制后就可以使用复杂的条件组合，flying 完全支持。</p>
<p>最后，updatePersist 操作不支持批量执行，因为它的特点是更新全部字段，批量处理不会得到您想要的结果，所以在 updatePersist 操作中入参的 <code>@ConditionMapperAnnotation</code> 注解仍然会被忽略。</p>
<h3 id="按复杂条件删除"><a href="#按复杂条件删除" class="headerlink" title="按复杂条件删除"></a><a href="#按复杂条件删除">按复杂条件删除</a></h3><p>从 <code>1.0.0</code> 开始加入按复杂条件删除操作。与按复杂条件修改类似，按复杂条件删除的入参要描述删除条件（在删除单条记录时我们只匹配主键），所以我们仍然采用 <i>pojo_condition</i> 类作为入参。pojo_condition 类是 pojo 类的子类，无需任何改动它就可以完成描述修改后的状态的任务；同时它又可以按需要加入各种 <code>@ConditionMapperAnnotation</code> 注解，以前版本删除操作会忽略这些注解，但从此版本开始这些注解会描述批量删除的条件，它们可以是复杂的组合，如 <code>&lt;&gt;</code>、<code>like</code>、<code>or</code> 等，只要您的数据库支持即可。仍以上一篇文章的AccountCondition为例，在AccountCondition中加入以下属性：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"name"</span>, conditionType = ConditionType.Equals)</span><br><span class="line">    <span class="comment">/*用作 name 完全匹配的值*/</span></span><br><span class="line">    <span class="keyword">private</span> String nameEquals;</span><br><span class="line"><span class="comment">/*相关的getter和setter方法请自行补充*/</span></span><br></pre></td></tr></table></figure></p>
<p>上面的代码看似和 Account 原有的 name 属性功能重复，但实际上因为它有 @ConditionMapperAnnotation 注解，在 delete 操作时可以作为批量处理条件：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">AccountCondition ac = <span class="keyword">new</span> AccountCondition();</span><br><span class="line">ac.setNameEqual(<span class="string">"ann"</span>);</span><br><span class="line"><span class="comment">/*将所有姓名为 ann 的用户都删除*/</span></span><br><span class="line">accountService.delete(ac);</span><br></pre></td></tr></table></figure></p>
<p>以上只是最简单的按复杂条件删除，当您理解这个机制后就可以使用复杂的条件组合，flying 完全支持。</p>
<h3 id="批量新增"><a href="#批量新增" class="headerlink" title="批量新增"></a><a href="#批量新增">批量新增</a></h3><p>从 <code>1.0.0</code> 开始加入批量新增操作。批量新增使用的 “action” 为 <code>&quot;insertBatch&quot;</code>，如下：<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"insertBatch"</span>&gt;</span></span><br><span class="line">	&#123;"action":"insertBatch", "keyGenerator":"uuid"&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>对应的 mapper 方法为（注意方法的入参）：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">insertBatch</span><span class="params">(Collection&lt;Account&gt; c)</span></span>;</span><br></pre></td></tr></table></figure></p>
<p>使用方法为：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Collection&lt;Account&gt; c = <span class="keyword">new</span> LinkedList&lt;&gt;();</span><br><span class="line">Account a1 = <span class="keyword">new</span> Account(), a2 = <span class="keyword">new</span> Account();</span><br><span class="line">a1.setName(<span class="string">"ann"</span>);</span><br><span class="line">c.add(a1);</span><br><span class="line">a2.setName(<span class="string">"bob"</span>);</span><br><span class="line">c.add(a2);</span><br><span class="line">accountMapper.insertBatch(c);</span><br></pre></td></tr></table></figure></p>
<p>这样一来就能以批量新增的方式增加两条数据（数据库只连接一次）。</p>
<p>在批量新增时不建议使用 mybatis 提供的自增主键方式，建议使用 flying-json 中的 <code>&quot;keyGenerator&quot;</code> 属性指定主键生成方式。</p>
<h3 id="批量更新"><a href="#批量更新" class="headerlink" title="批量更新"></a><a href="#批量更新">批量更新</a></h3><p>从 <code>1.0.1</code> 开始加入批量更新操作。批量更新使用的 “action” 为 <code>&quot;updateBatch&quot;</code>，如下：<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">update</span> <span class="attr">id</span>=<span class="string">"updateBatch"</span>&gt;</span></span><br><span class="line">	&#123;"action":"updateBatch"&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">update</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>对应的 mapper 方法为（注意方法的入参）：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">updateBatch</span><span class="params">(Collection&lt;Account&gt; c)</span></span>;</span><br></pre></td></tr></table></figure></p>
<p>使用方法为：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Collection&lt;Account&gt; c = <span class="keyword">new</span> LinkedList&lt;&gt;();</span><br><span class="line">Account a1 = <span class="keyword">new</span> Account(), a2 = <span class="keyword">new</span> Account();</span><br><span class="line">a1.setId(<span class="number">1</span>);</span><br><span class="line">a1.setName(<span class="string">"ann"</span>);</span><br><span class="line">c.add(a1);</span><br><span class="line">a2.setId(<span class="number">2</span>);</span><br><span class="line">a2.setName(<span class="string">"bob"</span>);</span><br><span class="line">c.add(a2);</span><br><span class="line">accountMapper.updateBatch(c);</span><br></pre></td></tr></table></figure></p>
<p>这样一来就能以批量更新的方式更新两条数据（数据库只连接一次）。</p>
<h2 id="索引"><a href="#索引" class="headerlink" title="索引"></a><a href="#索引">索引</a></h2><p>从 <code>1.0.0</code> 开始查询和计数操作可以使用索引，使用方法为在 json 的 <code>&quot;index&quot;</code> 属性中添加内容，例如 account 表的查询方法如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;select id=&quot;selectUseIndex&quot; resultMap=&quot;result&quot;&gt;</span><br><span class="line">	&#123;&quot;action&quot;:&quot;select#&#123;?&#125;&quot;, &quot;index&quot;:&quot;use index(index1)&quot;&#125;</span><br><span class="line">&lt;/select&gt;</span><br></pre></td></tr></table></figure></p>
<p>则生成的 sql 语句为：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select ... from account use index(index1) where account.id = ...</span><br></pre></td></tr></table></figure></p>
<p>您在 <code>&quot;index&quot;</code> 中输入的内容会正确的出现在索引的位置，除 “use index” 外您也可以使用 “force index” 和 “ignore index” 等。</p>
<h2 id="代理属性"><a href="#代理属性" class="headerlink" title="代理属性"></a><a href="#代理属性">代理属性</a></h2><p>从 <code>1.0.0</code> 开始对于关联对象的主键增加了一个代理属性，这是出于某些情况下优化性能的考虑。例如 Account 类中有一个关联属性 Role，如下：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FieldMapperAnnotation</span>(dbFieldName = <span class="string">"role_id"</span>, jdbcType = JdbcType.INTEGER, dbAssociationUniqueKey = <span class="string">"id"</span>)</span><br><span class="line"><span class="keyword">private</span> Role_ role;</span><br><span class="line"><span class="comment">/*相关的getter和setter方法请自行补充*/</span></span><br></pre></td></tr></table></figure></p>
<p>如果我们想查询 role_id 为 1 的结果集，以前我们需要这样做：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Account a = <span class="keyword">new</span> Account();</span><br><span class="line">Role r = <span class="keyword">new</span> Role();</span><br><span class="line">r.setId(<span class="number">1</span>);</span><br><span class="line">a.setRole(r);</span><br><span class="line">accountMapper.selectAll(a);</span><br></pre></td></tr></table></figure></p>
<p>为了避免只查询一个外键却要创建整个对象的开销，我们引入了代理机制，在 Account 中增加如下代码：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FieldMapperAnnotation</span>(dbFieldName = <span class="string">"role_id"</span>, jdbcType = JdbcType.INTEGER, delegate = <span class="keyword">true</span>)</span><br><span class="line"><span class="keyword">private</span> Integer delegateRoleId;</span><br><span class="line"><span class="comment">/*相关的getter和setter方法请自行补充*/</span></span><br></pre></td></tr></table></figure></p>
<p>如果我们想查询 role_id 为 1 的结果集，现在我们只需这样做：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Account a = <span class="keyword">new</span> Account();</span><br><span class="line">a.setDelegateRoleId(<span class="number">1</span>);</span><br><span class="line">accountMapper.selectAll(a);</span><br></pre></td></tr></table></figure></p>
<p>避免了创建新对象，自然也就提高了性能。</p>
<p>目前代理特性只适合于外键场景，并且建议您把这个代理变量的命名和被它代理的字段明显区分开（如名字前面统一加上 “delegate”），这可以防止您不使用代理属性时它却被错误的赋予了值，例如 mybatis 的自动 orm 机制。</p>
<h2 id="打印日志"><a href="#打印日志" class="headerlink" title="打印日志"></a><a href="#打印日志">打印日志</a></h2><p>从 <code>1.0.0</code> 开始加入打印生成的 sql 语句功能，方法为在 flying 的 plugin 配置中加入名为 “logLevel” 的 property，如下：<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">plugin</span> <span class="attr">interceptor</span>=<span class="string">"indi.mybatis.flying.interceptors.AutoMapperInterceptor"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"dialect"</span> <span class="attr">value</span>=<span class="string">"mysql"</span> /&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 对自动生成的sql的打印级别，可接受none、trace、debug、warn、error，默认为none，即不打印日志 --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"logLevel"</span> <span class="attr">value</span>=<span class="string">"error"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>当开启后 flying 在执行每一次操作时都会在指定级别进行打印，当然是否显示还要看您的日志文件配置。打印日志的格式如下：<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Auto generated sql:<span class="keyword">select</span> ...</span><br></pre></td></tr></table></figure></p>
<h1 id="清明"><a href="#清明" class="headerlink" title="清明"></a><a href="#清明">清明</a></h1><p>对应 flying 版本号为 <code>0.9.9</code>（适用于 mybatis-3.4.x），主要新增特性如下：</p>
<h2 id="支持更复杂的外键关系"><a href="#支持更复杂的外键关系" class="headerlink" title="支持更复杂的外键关系"></a><a href="#支持更复杂的外键关系">支持更复杂的外键关系</a></h2><p>在注解 <a href="https://gitee.com/limeng32/mybatis.flying/blob/master/src/main/java/indi/mybatis/flying/annotations/FieldMapperAnnotation.java" target="_blank" rel="noopener">@FieldMapperAnnotation</a> 中加入 <a href="https://gitee.com/limeng32/mybatis.flying/blob/master/src/main/java/indi/mybatis/flying/annotations/ForeignAssociation.java" target="_blank" rel="noopener">类型为 @ForeignAssociation[] 的新属性 associationExtra()</a>，例如为实现 ‘a left join b on (a.f_id = b.id and a.name_a = b.name_b and a.version_a &gt;= b.version_b and …)’，您可以使用如下代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FieldMapperAnnotation</span>(dbFieldName = <span class="string">"f_id"</span>, jdbcType = JdbcType.Integer, dbAssociationUniqueKey = <span class="string">"id"</span>, associationExtra = &#123;</span><br><span class="line">			<span class="meta">@ForeignAssociation</span>(dbFieldName = <span class="string">"name_a"</span>, dbAssociationFieldName = <span class="string">"name_b"</span>),</span><br><span class="line">			<span class="meta">@ForeignAssociation</span>(dbFieldName = <span class="string">"version_a"</span>, dbAssociationFieldName = <span class="string">"version_b"</span> ,condition=AssociationCondition.GreaterOrEqual) &#125;)</span><br></pre></td></tr></table></figure>
<p>同时在默认左外连接的基础上，增加了右外连接，实现方式为在注解 <a href="https://gitee.com/limeng32/mybatis.flying/blob/master/src/main/java/indi/mybatis/flying/annotations/FieldMapperAnnotation.java" target="_blank" rel="noopener">@FieldMapperAnnotation</a> 中加入 <a href="https://gitee.com/limeng32/mybatis.flying/blob/master/src/main/java/indi/mybatis/flying/statics/AssociationType.java" target="_blank" rel="noopener">新属性 associationType()</a>，例如为实现一个右外连接您可以使用如下代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FieldMapperAnnotation</span>(dbFieldName = <span class="string">"f_id"</span>, jdbcType = JdbcType.Integer, dbAssociationUniqueKey = <span class="string">"id"</span>, associationType = AssociationType.RightJoin)</span><br></pre></td></tr></table></figure>
<h1 id="阳春"><a href="#阳春" class="headerlink" title="阳春"></a><a href="#阳春">阳春</a></h1><p>对应 flying 版本号为 <code>0.9.4</code>（适用于 mybatis-3.4.x），主要新增特性如下：</p>
<h2 id="customTypeHandler"><a href="#customTypeHandler" class="headerlink" title="customTypeHandler"></a><a href="#customTypeHandler">customTypeHandler</a></h2><p>从 <code>0.9.4</code> 开始 <code>@FieldMapperAnnotation</code> 和 <code>@ConditionMapperAnnotation</code> 增加了 <code>customTypeHandler</code> 属性，使您可以用自定义的 TypeHandler 来处理变量映射，因为 <code>customTypeHandler</code> 具有最高优先级。</p>
<h1 id="初雪"><a href="#初雪" class="headerlink" title="初雪"></a><a href="#初雪">初雪</a></h1><p>对应 flying 版本号为 <code>0.8.3</code>（适用于 mybatis-3.3.x）和 <code>0.9.3</code>（适用于 mybatis-3.4.x），主要新增特性如下：</p>
<h2 id="自定义主键生成器"><a href="#自定义主键生成器" class="headerlink" title="自定义主键生成器"></a><a href="#自定义主键生成器">自定义主键生成器</a></h2><p>为满足个性化主键需要，flying 新增了自定义主键生成器，为此我们在 flying-json 中新增了 “keyGenerator” 属性，如下：<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">"keyGenerator":"uuid"                      使用标准uuid作主键</span><br><span class="line">"keyGenerator":"uuid_no_line"              使用无下横线的uuid作主键</span><br><span class="line">"keyGenerator":"millisecond"               使用毫秒数作主键（需保证每秒并发在1000以下）</span><br></pre></td></tr></table></figure></p>
<p>当然更多的情况是您会自定义自己的主键生成器，只要您的主键生成器实现了 flying 中的 indi.mybatis.flying.type.KeyHandler 接口即可，比如这样调用一个自定义的主键生成器类：<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">"keyGenerator":"indi.mybatis.flying.handlers.MySnowFlakeKeyHandler"</span><br></pre></td></tr></table></figure></p>
<p>（上面的 indi.mybatis.flying.handlers.MySnowFlakeKeyHandler 是一个雪花主键生成器的 java 版本实现。雪花主键生成器由 tweeter 发明用于处理大规模并行写入，主键采用 float 类型存储以节省资源，自带递增无需 order by，单台主机每秒可产生 400 万个不同主键，最多可 1024 台主机集群同时工作。flying 中提供了一个实现方式，<a href="https://gitee.com/limeng32/mybatis.flying/blob/master/src/main/java/indi/mybatis/flying/handlers/SnowFlakeKeyHandler.java" target="_blank" rel="noopener">代码见此</a>）</p>
<p>在某些特殊业务场景中，您需要使用主键表达一定的业务含义，这时自定义主键生成器会显得非常有效。</p>
<h2 id="使用或逻辑查询"><a href="#使用或逻辑查询" class="headerlink" title="使用或逻辑查询"></a><a href="#使用或逻辑查询">使用或逻辑查询</a></h2><h3 id="普通或逻辑查询"><a href="#普通或逻辑查询" class="headerlink" title="普通或逻辑查询"></a><a href="#普通或逻辑查询">普通或逻辑查询</a></h3><p>“或”逻辑查询是 <code>初雪</code> 版本新增的最重要内容。为了实现此特性 flying 新增了 Or 标签类（<a href="https://gitee.com/limeng32/mybatis.flying/blob/master/src/main/java/indi/mybatis/flying/annotations/Or.java" target="_blank" rel="noopener">代码见此</a>），这个标签的内容是ConditionMapperAnnotation标签的数组，所以在查询条件类中可以有如下标签代码：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Or</span>(&#123;</span><br><span class="line">  <span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"name"</span>, conditionType = ConditionType.HeadLike),</span><br><span class="line">  <span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"age"</span>, conditionType = ConditionType.Equal),</span><br><span class="line">  <span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"name"</span>, conditionType = ConditionType.HeadLike)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></p>
<p>（上面是实现 name like ‘XXX%’ or age = ‘YYY’ or name like ‘ZZZ%’ 查询的条件）</p>
<p>同时为了赋值方便，我们采用Object数组的不定参数形式作为变量类型，于是整个代码变成了：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Or</span>(&#123;</span><br><span class="line">  <span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"name"</span>, conditionType = ConditionType.HeadLike),</span><br><span class="line">  <span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"age"</span>, conditionType = ConditionType.Equal),</span><br><span class="line">  <span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"name"</span>, conditionType = ConditionType.HeadLike)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">private</span> Object[] condition1;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> Object[] getCondition1 () &#123;</span><br><span class="line">	<span class="keyword">return</span> condition1;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setCondition1</span> <span class="params">(Object... condition1)</span> </span>&#123;</span><br><span class="line">	<span class="keyword">this</span>. condition1 = condition1;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>如果我们描述 “name like ‘张%’ or age = 27 or name like ‘李%’ “，代码如下：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">personCondition.setCondition1(<span class="string">"张"</span>, <span class="number">27</span>, <span class="string">"李"</span>);</span><br><span class="line"><span class="comment">/* 注意参数顺序和 condition1 上 @ConditionMapperOrAnnotation 的内部顺序一致 */</span></span><br></pre></td></tr></table></figure></p>
<p>您之前掌握的<a href="https://gitee.com/limeng32/mybatis.flying/blob/master/src/main/java/indi/mybatis/flying/statics/ConditionType.java" target="_blank" rel="noopener">绝大部分 ConditionMapperAnnotation</a> 都可以写在 <code>@Or</code> 中，只有本身就是集合型的条件类型例外，以下列出不能进入 <code>@Or</code> 的类型：</p>
<p><code>MultiLikeAND</code>、<code>MultiLikeOR</code>、 <code>In</code>、<code>NotIn</code></p>
<p>除此之外的查询条件均可以参与或查询。</p>
<h3 id="外键或逻辑查询"><a href="#外键或逻辑查询" class="headerlink" title="外键或逻辑查询"></a><a href="#外键或逻辑查询">外键或逻辑查询</a></h3><p>flying 在同库跨表查询时也可以做不同表上条件的或逻辑查询，比如我们要实现 person.name = ‘XXX’ or role.name = ‘YYY’ 查询，其中 role 是 person 业务上的父对象。我们可以在 role 的条件类中加入如下变量：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Or</span>(&#123;</span><br><span class="line">  <span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"name"</span>, conditionType = ConditionType.Equal),</span><br><span class="line">  <span class="meta">@ConditionMapperAnnotation</span>(dbFieldName = <span class="string">"name"</span>, conditionType = ConditionType.Equal, subTarget = mypackage.Person.class) &#125;)</span><br><span class="line"><span class="keyword">private</span> Object[] roleNameEqualsOrPersonNameEquals;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> Object[] getRoleNameEqualsOrPersonNameEquals () &#123;</span><br><span class="line">	<span class="keyword">return</span> roleNameEqualsOrPersonNameEquals;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setRoleNameEqualsOrPersonNameEquals</span> <span class="params">(Object... roleNameEqualsOrPersonNameEquals)</span> </span>&#123;</span><br><span class="line">	<span class="keyword">this</span>. roleNameEqualsOrPersonNameEquals = roleNameEqualsOrPersonNameEquals;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>上面的代码中第一行 <code>ConditionMapperAnnotation</code> 指的是 role 表，第二行指的是 person 表，因为是由 role 指向 person，所以第二行出现了 <code>subTarget</code> 参数用来引导路径，它的值就是业务上子对象的类路径。</p>
<p>值得注意的是，外键或逻辑查询中，跨表的 <code>@Or</code> 条件永远要写在业务上的父对象里，这是考虑到从子对象上寻找父对象并非唯一（例如多重外键情况，一个 person 有多个 role 型父对象，分别表示主要角色和次要角色等），然而从父对象上寻找子对象永远是唯一的。</p>
<p>如果您要查询用户名为“张三”或角色名为“wfadmin”的用户时，您只需这样做：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">RoleConditon rc = <span class="keyword">new</span> RoleCondition();</span><br><span class="line">rc.setRoleNameEqualsOrPersonNameEquals(<span class="string">"wfadmin"</span>,<span class="string">"张三"</span>);</span><br><span class="line">Person p = <span class="keyword">new</span> Person();</span><br><span class="line">p.setRole(rc);</span><br><span class="line">Person&lt;Collection&gt; persons = personService.selectAll(p);</span><br></pre></td></tr></table></figure></p>
<p>无论 role 是 person 业务上的直接父对象还是间接父对象都可以这样查询。</p>
<h2 id="优化使用体验"><a href="#优化使用体验" class="headerlink" title="优化使用体验"></a><a href="#优化使用体验">优化使用体验</a></h2><p><code>@QueryMapperAnnotation</code> 现在可以省略，只要您的某个类既继承实体 pojo 又实现 Conditionable 接口 flying 就可以判断出它是相关 pojo 的条件类。当然这个标签出现在代码里也没有任何问题。</p>
<h2 id="全面提升代码质量"><a href="#全面提升代码质量" class="headerlink" title="全面提升代码质量"></a><a href="#全面提升代码质量">全面提升代码质量</a></h2><p>在 <code>初雪</code> 中，我们把代码质量作为提升的重要一环，同时使用 阿里 P3C 和 SonarQube 来修正代码缺陷，当您阅读 flying 源码时您会深切感受到这一点。</p>
  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/categories/blog/">blog</a>
</div>


</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://flying-doc.limeng32.com/2017/04/15/2017-04-15-flying 最新版本新增特性/" data-title="flying 最新版本新增特性 | my bat is flying in Aurora" data-tsina="" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2017/05/01/2017-05-01-使用flying解决pojo自动映射问题/" title="使用 flying 解决 pojo 自动映射问题">
  <strong>上一篇：</strong><br/>
  <span>
  使用 flying 解决 pojo 自动映射问题</span>
</a>
</div>


<div class="next">
<a href="/2017/03/01/2017-03-01-flying的发展方向/"  title="flying 的发展方向">
 <strong>下一篇：</strong><br/> 
 <span>flying 的发展方向
</span>
</a>
</div>

</nav>

	



</div>  
      <div class="openaside"><a class="navbutton" href="#" title="显示侧边栏"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">文章目录</strong>
 
 <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#极光"><span class="toc-text">极光</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#批量操作"><span class="toc-text">批量操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#按复杂条件修改"><span class="toc-text">按复杂条件修改</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#按复杂条件删除"><span class="toc-text">按复杂条件删除</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#批量新增"><span class="toc-text">批量新增</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#批量更新"><span class="toc-text">批量更新</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#索引"><span class="toc-text">索引</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#代理属性"><span class="toc-text">代理属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#打印日志"><span class="toc-text">打印日志</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#清明"><span class="toc-text">清明</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#支持更复杂的外键关系"><span class="toc-text">支持更复杂的外键关系</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#阳春"><span class="toc-text">阳春</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#customTypeHandler"><span class="toc-text">customTypeHandler</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#初雪"><span class="toc-text">初雪</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#自定义主键生成器"><span class="toc-text">自定义主键生成器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#使用或逻辑查询"><span class="toc-text">使用或逻辑查询</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#普通或逻辑查询"><span class="toc-text">普通或逻辑查询</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#外键或逻辑查询"><span class="toc-text">外键或逻辑查询</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#优化使用体验"><span class="toc-text">优化使用体验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#全面提升代码质量"><span class="toc-text">全面提升代码质量</span></a></li></ol></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="隐藏侧边栏"></a></div>
<aside class="clearfix">

  <div class="linkslist">
  <p class="asidetitle">友情链接</p>
    <ul>
        
          <li>
            
            	<a href="https://my.oschina.net/u/2280950/blog/1580056" target="_blank" title="关于在网络应用中使用双向相关模型的研究">flying-初雪 理论基础一</a>
            
          </li>
        
          <li>
            
            	<a href="https://my.oschina.net/u/2280950/blog/1594694" target="_blank" title="或逻辑的需求的实现方案">flying-初雪 理论基础二</a>
            
          </li>
        
          <li>
            
            	<a href="http://www.cnblogs.com/dasn/articles/5208022.html" target="_blank" title="为什么我们在初雪版中引入自定义主键机制">flying-初雪 新增自定义主键生成器特性</a>
            
          </li>
        
    </ul>
</div>

</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> God is in his heaven, all&#39;s right with the code. </p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		<a href="https://gitee.com/limeng32/mybatis.flying" target="_blank" class="icon-gitee" title="gitee"></a>
		
		
		<a href="https://github.com/limeng32/mybatis.flying" target="_blank" class="icon-github" title="github"></a>
		
		
		
		
		
		
		
		<a href="http://www.zhihu.com/people/li-meng-48" target="_blank" class="icon-zhihu" title="知乎"></a>
		
		
		
	</div>
			
		

	<p class="copyright">
		written by <a href="/about" target="_blank" title="limeng32">limeng32</a>
		© 2021
	</p>
</div>
</footer>
    <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.imagesloaded.min.js"></script>
<script src="/js/gallery.js"></script>
<script src="/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>











<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->





<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="返回顶部"><img src="/img/scrollup.png"/></a>
	</div>
	<script src="/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
